define(function(require, exports){
	var util = require('util');
	var pubjs = require('pubjs');
	var base = require('@base/common/base');

	// 选项卡 -媒体&广告位
	var MediaAndAds = base.tab.extend({
		init: function(config){
			// 区分RTB类型和监测类型
			var file = config.isRTB ? 'list': 'listMonitor';

			if(config && config.param) {
				//config.param.noAmount = true;
			}
			// 配置
			var list = {
				'spot': {
					text: LANG('广告位'),
					module: 'ads/grid/'+file+'.spot',
					config: {
						param: config.param,
						hasSearch: false,
						hasFilter: false,
						hasDateRange: true
					}
				},
				'spotSize': {
					text: LANG('尺寸'),
					module: 'ads/grid/'+file+'.size',
					config: {
						param: config.param,
						url: 'spot/subSize',
						subgrid_title_field: 'Size',
						hasSearch: false,
						hasFilter: false,
						hasDateRange: true
					}
				},
				'domain': {
					text: LANG('媒体域名'),
					module: 'ads/grid/'+file+'.domain',
					config: {
						param: config.param,
						subgrid_title_field: 'referer_domain_title',
						hasSearch: false,
						hasFilter: false,
						hasDateRange: true
					}
				},
				'spotChannel': {
					text: LANG('渠道'),
					module: 'ads/grid/'+file+'.channel',
					config: {
						param: config.param,
						subgrid_title_field: 'channel_name',
						hasSearch: false,
						hasFilter: false,
						hasDateRange: true
					}
				},
				'spotScreen': {
					text: LANG('屏次'),
					module: 'ads/grid/'+file+'.screens',
					config: {
						param: config.param,
						subgrid_title_field: 'ScreenName',
						hasSearch: false,
						hasFilter: false,
						hasDateRange: true
					}
				}
			};

			list = this.formatParam(config.param, list);

			config = pubjs.conf(config, {
				'async': true,
				'list': list,
				'uuid': util.uuid()
			});
			this.Super('init', arguments);
		},
		// 实现选项卡的层层递减，eg: 父层有尺寸，子层就不要出现尺寸
		formatParam: function(subParam, list){
			if(!subParam.condition){
				pubjs.error(LANG('无condition参数'));
				return false;
			}

			subParam = subParam.condition;

			if(util.isString(subParam)){
				subParam = JSON.parse(subParam);
			}

			var mapping = {
				'spot_id': 'spot',					// 广告位
				'referer_domain_id': 'domain',		// 媒体域名
				'channel_id': 'spotChannel',		// 渠道
				'spot_size_id': 'spotSize',			// 尺寸
				'spot_screen_id': 'spotScreen'		// 屏次
			};

			for (var i = 0; i < subParam.length; i++) {
				// 每一组condition参数；类型为对象
				var group = subParam[i];

				// condition_id
				for(var name in group){
					if(mapping[name]){
						// 从list中删掉
						list[mapping[name]] = null;
					}
				}
			}

			return list;
		}
	});
	exports.base = MediaAndAds;

	// 简单版 选项卡 -媒体&广告位
	var MediaAndAdsLite = base.tab.extend({
		init: function(config){
			// 区分RTB类型和监测类型
			var file = config.isRTB ? 'list': 'listMonitor';

			if(config && config.param) {
				//config.param.noAmount = true;
			}
			// 配置
			var list = {
				'spot': {
					text: LANG('广告位'),
					module: 'ads/grid/'+file+'.liteSpot',
					config: {
						param: config.param,
						hasSearch: false,
						hasFilter: false
					}
				},
				'spotSize': {
					text: LANG('尺寸'),
					module: 'ads/grid/'+file+'.liteSize',
					config: {
						param: config.param,
						url: 'spot/subSize',
						subgrid_title_field: 'Size',
						hasSearch: false,
						hasFilter: false
					}
				}
			};

			list = this.formatParam(config.param, list);

			config = pubjs.conf(config, {
				'async': true,
				'list': list
			});
			this.Super('init', arguments);
		},
		// 实现选项卡的层层递减，eg: 父层有尺寸，子层就不要出现尺寸
		formatParam: function(subParam, list){
			if(!subParam.condition){
				pubjs.error(LANG('无condition参数'));
				return false;
			}

			subParam = subParam.condition;

			if(util.isString(subParam)){
				subParam = JSON.parse(subParam);
			}

			var mapping = {
				'spot_id': 'spot',					// 广告位
				'referer_domain_id': 'domain',		// 媒体域名
				'channel_id': 'spotChannel',		// 渠道
				'spot_size_id': 'spotSize',			// 尺寸
				'spot_screen_id': 'spotScreen'		// 屏次
			};

			for (var i = 0; i < subParam.length; i++) {
				// 每一组condition参数；类型为对象
				var group = subParam[i];

				// condition_id
				for(var name in group){
					if(mapping[name]){
						// 从list中删掉
						list[mapping[name]] = null;
					}
				}
			}

			return list;
		}
	});
	exports.lite = MediaAndAdsLite;

});